package com.happyrecyclingstation.controller.hr;

import com.happyrecyclingstation.dto.PosHrQueryDto;
import com.happyrecyclingstation.dto.PosHrSaveDto;
import com.happyrecyclingstation.service.PositionService;
import com.happyrecyclingstation.utils.Result;
import com.happyrecyclingstation.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业用户
 */
@Slf4j
@RestController("hrPositionController")
@RequestMapping("/hr/positions")
public class PositionController {
    @Autowired
    private PositionService positionService;

    /**
     * HR分页查询职位列表
     * @param hrQueryParam
     * @return
     */
    @GetMapping
    public Result getPositions(PosHrQueryDto hrQueryParam) {
        log.info("hr分页查询参数：{}", hrQueryParam);
        PageResult<HrPosVO> pageResult = positionService.hrGetList(hrQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 保存职位信息
     * @param posHrSaveDto
     * @return
     */
    @PostMapping
    public Result savePosition(@RequestBody PosHrSaveDto posHrSaveDto) {
        log.info("保存职位信息：{}", posHrSaveDto);
        positionService.savePosition(posHrSaveDto);
        return Result.success();
    }

    /**
     * 查询职位详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getPosDetail(@PathVariable("id") Integer id){
        log.info("查询职位详情：{}", id);
        PosHrSaveVO posHrSaveVo = positionService.getPosHrById(id);
        return Result.success(posHrSaveVo);
    }

    /**
     * 修改职位信息
     * @param posHrSaveDto
     * @return
     */
    @PutMapping
    public Result updatePosition(@RequestBody PosHrSaveDto posHrSaveDto) {
        log.info("修改职位信息：{}", posHrSaveDto);
        positionService.updatePosition(posHrSaveDto);
        return Result.success();
    }

    /**
     * 批量删除职位信息
     * @param ids
     * @return
     */
    @DeleteMapping
    public Result deletePosition(@RequestParam("ids") List<Integer> ids) {
        log.info("删除职位信息：{}", ids);
        positionService.deletePosition(ids);
        return Result.success();
    }

    /**
     * 获取职位名称列表
     */
    @GetMapping("/names")
    public Result getPosName() {
        log.info("获取职位名称列表");
        List<HrPosNameVO> list = positionService.getPosName();
        return Result.success(list);
    }
}
